export function stripScript(content) {
  const result = content.match(/<(script)>(\s\S)<\/\1>/)
  return result && result[2] ? result[2].trim() : ''
}

export function stripStyle(content) {
  const result = content.match(/<(style)\s*>([\s\S]+)<\/\1>/)
  return result && result[2] ? result[2].trim() : ''
}

export function stripTemplate(content) {
  content = content.trim()
  if (!content) {
    return content
  }
  return content.replace(/<(script|style)[\s\S]+<\/\1>/g, '').trim()
}

const separate = (str = '') => {
  let splitArr = str.split(/export\s*default\s*\{/)

  return {
    imports: splitArr[0] && splitArr[0],
    jsContent: splitArr[1] && splitArr[1].replace(/(\}\s*;?\s*)$/, '')
    // jsContent: splitArr[1] && eval('({' + splitArr[1] + ')')
  }
}

export function match(str) {
  let template = str.match(/<template>([\s\S]*)<\/template>/i, '$1')
  let script = str.match(/<script>([\s\S]*)<\/script>/i, '$1')
  let style = str.match(/<style>([\s\S]*)<\/style>/i, '$1')
  let { imports, jsContent } = separate(script[1])

  return {
    template: template && template[1],
    imports,
    jsContent,
    style: style && style[1]
  }
}